<template>
  <div class="catalogList">
    <filterPanel filterName="CCatalogListFilter" filterTitle="目录查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="CCatalogListTable" :tableLoading="loading" tableTitle="目录列表" :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <zy-button type="primary" @click="tableClick('', 'add')">新增目录</zy-button>
    </tablePanel>
    <zyModel :show="showModel" title="新增目录" :showBtn="false" @close="hideModel">
      <div class="addCatalog">
        <div class="inputArea">
          <div class="inputTitle required">目录名</div>
          <div class="inputContent">
            <zy-input v-model="catalogName" maxlength="50"></zy-input>
          </div>
        </div>
        <div class="btnArea">
          <zy-button class="btn" @click="hideModel">取消</zy-button>
          <zy-button class="btn" type="primary" @click="saveFace">确定</zy-button>
          <zy-button class="btn" type="primary" @click="saveFace(true)">确定且上传</zy-button>
        </div>
      </div>
    </zyModel>
  </div>
</template>

<script>
	export default {
		name: "CCatalogList",
		props: {},
		data() {
			return {
				filterData: [
					{
						title: '目录名',
						name: 'face_name',
						type: 'input',
						value: '',
						maxlength: '50',
						isShow: true,
						isSelected: true
					},
					{
						title: '创建人',
						name: 'create_user_name',
						maxlength: '20',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '创建时间',
						name: 'time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
				],
				form: {
					face_name: '',
					create_user_name: '',
					time: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '目录名',
						name: 'face_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '创建人',
						name: 'create_user_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '创建时间',
						name: 'create_time_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 100,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'look',
								name: '详情'
							},
						],
						isSelected: true
					}
				],
				tableData: [],
				total: 0,
				showModel: false,
				catalogName: '',
				face_id: ''
			};
		},
		computed: {
			postData() {
				let data = {
					...this.form,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.time && this.form.time.length > 0) {
					data.create_time_start = this.form.time[0] / 1000;
					data.create_time_end = this.form.time[1] / 1000;
				}
				return data;
			},
		},
		watch: {},
		components: {},
		methods: {
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.$axios.post(this.$api.c_getFaceList, this.postData).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.tableData = data.list.filter(item => {
							item.look = true;
							return item;
						});
						this.total = data.pagination.total_count || 0;
					} else {
						this.total = 0;
						this.tableData = [];
					}
				}).catch(ret => {
					this.loading = false;
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			tableClick(data, type) {
				if (type === 'add') {
					this.catalogName = '';
					this.showModel = true;
				} else {
					this.$toRoutePath({
						path: "/cooperate/catalog/detail",
						edit: true,
						query: {
							type: type,
							face_id: data.face_id
						}
					});
				}
			},
			hideModel() {
				this.showModel = false;
			},
			saveFace(isJump) {
				if (!this.catalogName) {
					return this.$message.error('请输入目录名称');
				}
				this.$axios.post(this.$api.c_saveFace, {
					face_id: this.face_id,
					face_name: this.catalogName
				}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.getData();
						if (isJump) {
							this.$toRoutePath({
								path: "/cooperate/catalog_import",
								edit: true,
								query: {}
							});
						}
						this.hideModel()
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			}
		},
		mounted() {
			this.getData();
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/cooperate/catalog/catalogList/index.less">

</style>
